#include<bits/stdc++.h>
using namespace std;
#define int long long

int n;
bool col[15];
bool vis[15][15];
int ans[15];

bool check(int x, int y) {
	if (col[y])	return false;
	for (int i = x - 1, j = y - 1; i > 0 && j > 0; i--, j--) {
		if (vis[i][j])	return false;
	}
	for (int i = x - 1, j = y + 1; i > 0 && j <= n; i--, j++) {
		if (vis[i][j])	return false;
	}
	return true;
}

int cnt_ans;

void dfs(int k) {
	if (k == n) {
		cnt_ans++;
		if (cnt_ans > 3)
			return ;

		for (int i = 1; i <= n; i++) {
			cout << ans[i] << " ";
		}
		cout << endl;
		return ;
	}
	for (int i = 1; i <= n; i++) {
		if (check(k + 1, i)) {
			col[i] = 1;
			vis[k + 1][i] = 1;
			ans[k + 1] = i;
			dfs(k + 1);
			col[i] = 0;
			vis[k + 1][i] = 0;
		}
	}
}

signed main() {
	cin >> n;
	dfs(0);
	cout << cnt_ans;
	return 0;
}
